@extends('admin.layout')
@section('content')
    @if ($message = Session::get('success'))
        <div class="layui-card">
            <div class="layui-card-header">提示！</div>
            <div class="layui-card-body">
                <p>{{ $message }}</p>
            </div>
        </div>
    @endif
    <div class="layui-card">

        <div class="layui-card-body">
            <div class="layui-btn-group layui-left-menu">
                <a  href="{{route('admin.category.create',['type'=>$type??'post'])}}" class="layui-btn "><i class="fa fa-plus-circle"></i> 添加分类</a>
                {{--<a  href="{{route('admin.category.destroy')}}" class="layui-btn layui-btn-danger ajax-batch-del"><i class="fa fa-trash-o"></i> 批量删除</a>--}}

            </div>
            <table id="dataTable" lay-filter="dataTable"></table>
            <script type="text/html" id="options">
                <div class="layui-btn-group">
                    <a class="layui-btn layui-btn-sm" href="{{route('admin.category.create')}}?id=@{{d.id}}&type={{$type??'post'}}" lay-event="edit">添加子类</a>
                    <a class="layui-btn layui-btn-sm" href="/admin/category/edit/@{{d.id}}/" lay-event="edit">编辑</a>
                    <a  class="layui-btn layui-btn-danger layui-btn-sm ajax-del" href="{{route('admin.category.destroy')}}" data-id="@{{d.id}}" >删除</a>
                </div>
            </script>
        </div>
    </div>
@endsection

@section('script')
    <script>
        layui.use(['table','form','layer'], function(){
           var table = layui.table;
            var dataTable = table.render({
                elem: '#dataTable'
                ,url: "{{ route('admin.category.data') }}" //数据接口
                ,where:{type:"{{$type??'post'}}"}
                ,page: false //开启分页
                ,cols: [[ //表头

                    {field: 'id', title: 'ID', sort: true,width:80}
                    ,{field: 'cat_name', title: '名称'}
                    ,{field: 'type', title: '所属类型'}
                    ,{field: 'thumb', title: '缩略图', templet: function(data){
                        return '<a  class="view-img" href="'+data.thumb+'" ><image style="max-width:30px;max-height:30px;" src="'+data.thumb+'"/></a>';
                    }}
                    ,{field: 'value', title: '排序'}
                    ,{fixed: 'right',  align:'center', toolbar: '#options'}
                ]]
            });
        });
    </script>
@endsection